import fetch from 'common/src/utils/fetch';
import UTILS from "common/src/utils/utils";
// let apiPrefix = '/dev';
let apiPrefix = '/api/studentservice/';
/**
 * 分页查询
 * @param {data} data
 */
export function findListPage(data) {
  return fetch({
    url: apiPrefix + 'assessStudentNameController/page',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 新增
 */
export function addRequirePaperStudent(data) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/addRequirePaperStudent',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 *修改
 * @param data
 */
export function updateRequirePaperStudent(data) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/updateRequirePaperStudent',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 查询
 * @param data
 */
export function getRequirePaperStudentById(id) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/getRequirePaperStudentById?id='+id,
    method: 'get'
  })
}

/**
 * 删除
 * @param id
 */
export function deleteRequirePaperStudent(id) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/deleteRequirePaperStudent?id='+id,
    method: 'get'
  })
}

/**
 * 批量删除
 * @param id
 */
export function deleteStudentList(idList) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/deleteStudentList',
    method: 'post',
    data:{
      ids:idList
    }
  })
}

/**
 * 发布与取消发布接口
 * @param idList
 */
export function updatePublishStatus(data) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/updatePublishStatus',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 一次性全部发布
 */
export function updateAllPublishStatus(data) {
  return fetch({
    url: apiPrefix + 'assessStudentNameController/updateAllPublishStatus',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: data
  })
}

/**
 * 获取名单接口
 * @param id
 */
//
export function getStudentList(calendarId,faculty,profession,deptId) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/getStudentList?calendarId='+calendarId+"&faculty="+faculty+"&profession="+profession+"&deptId="+deptId,
    method: 'get'
  })
}
/**
 * 获取一直未通过名单
 * */
export function getNoPassStudentList(calendarId,faculty,profession,deptId) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/getNoPassStudentList?calendarId='+calendarId+"&faculty="+faculty+"&profession="+profession+"&deptId="+deptId,
    // url:apiPrefix + 'assessStudentNameController/getNoPassStudentList',
    method: 'get'
  })
}
/*
* 根据学生学号获取学生信息
* */
export function selectStudentInfoByStuId(studentId) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/selectStudentInfoByStuId?studentId='+studentId,
    method: 'get'
  })
}

/**
 * 导出表单
 * @param data
 */
// export function exportDepartureList(data) {
//   return fetch({
//     url:apiPrefix + 'assessStudentNameController/exportDepartureList',
//     method: 'get',
//   }).then(res => {
//     UTILS.downloadFile(res, 'nameList.xlsx', 'application/vnd.ms-excel;charset=utf-8');
//   });
// }

//导出
export function exportNameList(data = {}) {
  let keys = Object.keys(data).map(item => {return item;});
  let params = keys.reduce((prev, curr, index) => {
    prev += curr + '=' + data[curr];
    if (index < keys.length - 1) {
      prev += '&';
    }
    return prev;
  }, '');
  let url = '/api/studentservice/assessStudentNameController/exportNameList';
  params && (url += `?${params}`);
  window.open(url);
}

export function exportNameList2(data) {
  return fetch({
    url:apiPrefix + 'assessStudentNameController/exportNameList2',
    method: 'post',
    data: data,
    responseType: 'blob'
  }).then(res => {
      UTILS.downloadFile(res, 'AssessNameList.xls', 'application/vnd.ms-excel;charset=utf-8');
  });
}


export default {
  findListPage,
  addRequirePaperStudent,
  updateRequirePaperStudent,
  getRequirePaperStudentById,
  deleteRequirePaperStudent,
  deleteStudentList,
  updatePublishStatus,
  updateAllPublishStatus,
  selectStudentInfoByStuId,
  exportNameList,
  exportNameList2,
  getStudentList,
  getNoPassStudentList
}


